package com.hpf.tool.redis.interfaces.handle.impl;

import com.hpf.tool.interfaces.ICallable;
import com.hpf.tool.redis.exceptions.HJedisException;
import com.hpf.tool.redis.interfaces.handle.IHJedisString;
import com.hpf.tool.redis.interfaces.impl.HBaseJedis;

import redis.clients.jedis.Jedis;

/**
 * 数据类型 - String Jedis
 * @author houbinfei
 *
 */
public final class HJedisString extends HBaseJedis<String> implements IHJedisString{
	/**
	 * 校验 - String： key and value is empty ?
	 * @param key
	 * @param value
	 */
	private void verifyData(final String key,final String value){
		super.verifyKey(key);
		
		if(value == null || "".equals(value)){
			throw new HJedisException(false,"value is empty.");
		}
	}
	@Override
	public void set(final String key, final String value) {
		
		this.verifyData(key, value);
		
		super.callBack(new ICallable.ICallableI<Jedis>() {
			@Override
			public void exce(Jedis jedis) {
				jedis.set(key, value);
			}
		});
	}

	@Override
	public void set(final String key, final String value, final int expireTime) {
		
		this.verifyData(key, value);
		
		super.callBack(new ICallable.ICallableI<Jedis>() {
			@Override
			public void exce(Jedis jedis) {
				jedis.setex(key, expireTime == 0 ? 1000 : expireTime, value);
			}
		});
	}
}
